<jsp:include page="logincheck.jsp" />
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ page import="java.util.*" %>

<jsp:useBean id="phoneAccount" class="se2.PhoneAccount" scope="request"/>
<jsp:setProperty name="phoneAccount" property="*"/>

<jsp:useBean id="billingPlans" class="se2.BillingPlan" scope="request"/>
<jsp:setProperty name="billingPlans" property="*"/>

<%
	//phoneAccount = new se2.PhoneAccount(Integer.valueOf(request.getParameter("id")));
	phoneAccount.setId(Integer.valueOf(request.getParameter("id")));
	phoneAccount.getPhoneAccountFromDatabase();
%>

<html>

	<head>
		<title>Administration Console</title>
		<link rel="stylesheet" href="default.css" type="text/css" media="screen"></link>
		<script type="text/javascript" language="javascript" src="addPhoneAccount.js"></script>
	</head>

	<body>
		<div id="container">
			<div id="navigation">
<p>&nbsp;</p>
<jsp:include page="navigation.jsp" />
			</div>
			
			<div id="header">				
				<img src="images/header.png" />
			</div>

			<div id="content">
<!-- Main code -->

<h1>Customer Accounts :: Edit Phone Account</h1>

<form name="addPhone" id="addPhone" method="post" action="editPhoneAccountFunction.jsp?cid=<%= request.getParameter("cid") %>&id=<%= request.getParameter("id") %>&ext=<%= phoneAccount.getExtension() %>&ip=<%= phoneAccount.getIpAddress() %>&perm=<%= phoneAccount.getPermissions() %>&bp=<%= phoneAccount.getBillingPlan() %>" onSubmit="return validate(this);">
	<table border="0" cellpadding="0" cellspacing="0" width="100%">
		<tr>
			<td colspan="2"><span id="errorMessages"></span></td>
		</tr>
		<tr style="background-image: url('images/tableBackground.png');">
			<td class="tableHeader">Phone Extension</td>
			<td><input type="text" id="extension" name="extension" maxlength="4" class="textField" onClick="this.style.background='#efefef';" onBlur="this.style.background='#fff';"
				value="<%= phoneAccount.getExtension() %>" /></td>
		</tr>
		
		<tr>
			<td class="tableHeader">Phone IP Address</td>
			<td><input id="ipAddress" name="ipAddress" class="textField" onClick="this.style.background='#efefef';" onBlur="this.style.background='#fff';"
				value="<%= phoneAccount.getIpAddress() %>" ></td>
		</tr>
		
		<tr style="background-image: url('images/tableBackground.png');">
			<td class="tableHeader">Permissions</td>
			<td>
			
<% 
			int perm=phoneAccount.getPermissions();
%>
			
				<select id="permissions" name="permissions" style="margin: 5px;" class="textField">
					<option value="">Select</option>
					<option value="0" <% if (perm == 0){ %>selected<% } %> >Disabled</option>
					<option value="1" <% if (perm == 1){ %>selected<% } %> >Incoming & Outgoing</option>
					<option value="2" <% if (perm == 2){ %>selected<% } %> >Incoming Only</option>
					<option value="3" <% if (perm == 3){ %>selected<% } %> >Outgoing Only</option>
				</select>
			</td>
		</tr>
		
		<tr>
			<td class="tableHeader">Billing Plan</td>
			<td>
			
<% 
			//int bpNum=phoneAccount.getBillingPlan();
			//System.out.println(phoneAccount.getBillingPlan());
%>

				<select id="billingPlan" name="billingPlan" style="margin: 5px;" class="textField">
					<option value="">Select</option>
				<c:forEach var="bp" items="${billingPlans.allBillingPlans}">
					<option value="${bp.id}"${bp.id == phoneAccount.billingPlan ? ' selected' : ''} >${bp.name}</option>
				</c:forEach>
				</select>
			</td>
		</tr>
							
		<tr>
			<td colspan="2" align="right">
				<input type="submit" value="Submit" />
				<input type="button" value="Cancel" onclick="javascript:document.location.href='viewCustomerAccountDetails.jsp?id=<%= phoneAccount.getCustomerId() %>'" />
			</td>
		</tr>
	</table>
</form>

<!-- Main Code -->
			</div>

			<div id="footer">
<jsp:include page="footer.jsp" />
			</div>
		</div>
	</body>

</html>